import { useState, useEffect } from 'react'
import { getSecretLevels } from '../../service'
function useSecretlevel(props: any) {
  const { options } = props
  const [newfileschemaOptions, $newfileschemaOptions] = useState(options)

  useEffect(() => {
    getSecretLevels().then(res => {
      if (res.result == 0) {
        const fileOptions = newfileschemaOptions.map(item => {
          if (item.key === 'securitylevelid') {
            item.options = res.secLevelList.map(ele => {
              return {
                text: ele.SecLevelName, 
                value: ele.SecLevelId
              }
            })
          }
          return item
        })
        $newfileschemaOptions(fileOptions)
      }
    })

  }, [])
  return newfileschemaOptions;
}

export default useSecretlevel;
